<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

<input type="text" id="message">
<button id="submit">提交</button>

<script>
    
     //创建websocket对象
    let websocket = new WebSocket("ws://127.0.0.1:59090/test");

    //提供回调函数

    websocket.onopen=function(){
        console.log("连接建立");
    }
   
    websocket.onmessage=function(e){
       console.log("收到消息"+e.data);
       location.href="/login.html";
    }
    websocket.onerror=function(){
         console.log("连接异常");
    }
    websocket.onclose=function(){
        console.log("连接关闭");
    }

    let message = document.querySelector('#message');
    let buttonn = document.querySelector('#submit');
   

   buttonn.onclick=function(){
    console.log("发送消息"+message.value);
    websocket.send(message.value);
   }

</script>
    
</body>
</html>